home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CPolygon.cp < prev    next >
Text File  |  1994-04-27  |  4KB  |  146 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| This file contains the implementation of the CPolygon class.  A CPolygon
  3. //| is a graphics primitive.  It implements an optionally filled closed polygon,
  4. //| with an optional border.
  5. //|________________________________________________________________________________
  6.  
  7.  
  8. #include "CPolygon.h"
  9. #include <CList.h>
  10.  
  11.  
  12. //============================ Prototypes ============================\\
  13.  
  14.  
  15.  
  16. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  17. //| CPolygon::IPolygon
  18. //|
  19. //| Purpose: Initialize a CPolygon.
  20. //|
  21. //| Parameters: colors:   the color list
  22. //|_________________________________________________________
  23.  
  24. void CPolygon::IPolygon(CList *colors)
  25. {
  26.  
  27.     CPrimitive::IPrimitive(colors);                    //  Initialize superclass
  28.  
  29.     polygon_vertex_indices = new(CList);            //  Initialize the polygon vertex index list
  30.     polygon_vertex_indices->IList();
  31.     
  32. }    //==== CPolygon::IPolygon() ====\\
  33.  
  34.  
  35.  
  36. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. //| CPolygon::Dispose
  38. //|
  39. //| Purpose: Dispose of the polygon.
  40. //|
  41. //| Parameters: none
  42. //|_________________________________________________________
  43.  
  44. void CPolygon::Dispose(void)
  45. {
  46.  
  47.     polygon_vertex_indices->Dispose();                //  Get rid of the polygon vertex index list
  48.  
  49.     CPrimitive::Dispose();                            //  Dispose of superclass
  50.  
  51. }    //==== CPolygon::Dispose() ====\\
  52.  
  53.  
  54.  
  55. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. //| Operator >> to extract CPolygon from stream
  57. //|
  58. //| Purpose: Read this polygon from the input stream
  59. //|
  60. //| Parameters: none
  61. //|_________________________________________________________
  62.  
  63. istream& operator>> (istream& s, CPolygon& p)
  64. {
  65.  
  66.     s >> p.color_index;                                            //  Get index of interior color
  67.     s >> p.boundary_color_index;                                //  Get index of boundary color
  68.     
  69.     short num_vertices;                                            //  Get number of vertices
  70.     s >> num_vertices;    
  71.  
  72.     short i;
  73.     for (i = 1; i <= num_vertices; i++)
  74.         {
  75.         long vertex_index;                                        //  Get index of the vertex
  76.         s >> vertex_index;    
  77.         
  78.         p.polygon_vertex_indices->Append((CObject *) vertex_index);//  Add this point to the polygon
  79.         }
  80.     
  81.     return s;
  82.     
  83. }    //==== Operator >> to extract CPolygon from stream ====\\
  84.  
  85.  
  86.  
  87. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. //| CPolygon::Draw
  89. //|
  90. //| Purpose: Draw this polygon.
  91. //|
  92. //| Parameters: override_color:  the color to use to draw the primitive
  93. //|                              If this is NULL, use the primitive's default
  94. //|             screen_vertices: the screen coordinates of the vertices
  95. //|             clip_rect:       the clipping rectangle
  96. //|             fAntialias:      TRUE if we should antialias
  97. //|__________________________________________________________________________
  98.  
  99. void CPolygon::Draw(RGBColor *override_color, Point **screen_vertices,
  100.                     Rect *clip_rect, Boolean fAntialias)
  101. {
  102.  
  103.     PolyHandle polygon = OpenPoly();                            //  Start recording a polygon
  104.  
  105.     long vertex_index =
  106.                     (long) polygon_vertex_indices->NthItem(1);    //  Get index of first point
  107.     
  108.     Point screen_point = *(*screen_vertices + vertex_index);    //  Get the screen point
  109.  
  110.     MoveTo(screen_point.h, screen_point.v);                        //  Start here
  111.  
  112.     short num_vertices = polygon_vertex_indices->GetNumItems();    //  Get number of points
  113.  
  114.     short i;
  115.     for (i = 1; i < num_vertices; i++)
  116.         {
  117.         
  118.         vertex_index =
  119.                     (long) polygon_vertex_indices->NthItem(i);    //  Get index of this point
  120.         
  121.         Point screen_point = *(*screen_vertices + vertex_index);//  Get the screen point
  122.  
  123.         LineTo(screen_point.h, screen_point.v);                    //  Draw the line segment
  124.  
  125.         }
  126.  
  127.     ClosePoly();                                                //  Stop recording a polygon
  128.  
  129.     if (override_color)
  130.         RGBForeColor(override_color);                            //  Use specified color, if any
  131.  
  132.     else
  133.         RGBForeColor(*((RGBColor **) colors->
  134.                             NthItem(boundary_color_index)));    //  Use default outline color
  135.  
  136.     FramePoly(polygon);                                            //  Draw the polygon's outline
  137.  
  138.     if (!override_color)
  139.         RGBForeColor(*((RGBColor **) colors->
  140.                             NthItem(color_index)));                //  Use default fill color
  141.  
  142.     PaintPoly(polygon);                                            //  Fill the polygon
  143.  
  144.     KillPoly(polygon);                                            //  Get rid of polygon
  145.  
  146. }    //==== CPolygon::Draw() ====\\